package com.aleaho.cftrack.activity;

import android.annotation.TargetApi;
import android.app.ActivityOptions;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

import android.transition.Explode;
import android.transition.Slide;
import android.transition.TransitionInflater;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.view.WindowManager;
import android.widget.Toast;

import com.aleaho.cftrack.CFTrackApplication;
import com.aleaho.cftrack.R;
import com.aleaho.cftrack.presenter.SplashPresenter;
import com.aleaho.cftrack.utils.Constants;
import com.aleaho.cftrack.utils.ViewUtil;
import com.aleaho.cftrack.view.SplashView;


public class SplashActivity extends AppCompatActivity implements SplashView {


    SplashPresenter splashPresenter = null;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);

        setContentView(R.layout.activity_splash);
        setupWindowAnimations();
        splashPresenter = new SplashPresenter(this, (CFTrackApplication) getApplicationContext());

        //        ViewUtil.setupWindowExitExpldeAnimations(this, (Context) this);

        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                splashPresenter.checkLoginStatus();
            }
        }, Constants.SPLASH_TIME);
    }


    @TargetApi(22)
    private void setupWindowAnimations() {
        Explode explode = new Explode();//(Slide)TransitionInflater.from(this).inflateTransition(R.transition.activity_slide);
        explode.setDuration(1500);
        //        explode.setSlideEdge(Gravity.END);
        getWindow().setExitTransition(explode);
    }


    @Override
    public void turnToMain() {
        Intent mIntent = new Intent(this, MainActivity.class);
        startActivity(mIntent);
        overridePendingTransition(R.anim.in_from_right, R.anim.keep);
    }

    @Override
    public void turnToLogin() {
        Intent mIntent = new Intent(this, LoginActivity.class);
        startActivity(mIntent);
        overridePendingTransition(R.anim.in_from_right, R.anim.keep);
    }


    @Override
    protected void onStop() {
        super.onStop();

        finish();
    }
}
